package model

import (
	uuid "github.com/satori/go.uuid"
	"gorm.io/gorm"
)

type Order struct {
	gorm.Model
	OrderNo        uuid.UUID `gorm:"type:varchar(50);not null;unique" json:"order_no"`
	InstrumentID   uint      `gorm:"type:int;not null" json:"instrument_id"`
	Num            uint      `gorm:"type:int;not null" json:"num"`
	UserID         uint      `gorm:"type:int;not null" json:"user_id"`
	Status         string    `gorm:"type:varchar(20);not null" json:"status"`
	TransportWay   string    `gorm:"type:varchar(20);not null" json:"transport_way"`
	InstrumentName string    `gorm:"type:varchar(100);not null" json:"instrument_name"`
	InstrumentImg  string    `gorm:"type:varchar(500);not null" json:"goods_img"`
	UserName       string    `gorm:"type:varchar(20);not null" json:"user_name"`
}

func (p *Order) BeforeCreate(tx *gorm.DB) (err error) {
	p.OrderNo = uuid.NewV1()
	return nil
}
